//
//  InfomationViewController.swift
//  FirstSwiftProduct
//
//  Created by 知合金服-Mini on 2017/12/5.
//  Copyright © 2017年 范泽华. All rights reserved.
//

import UIKit

class InfomationViewController: BasePushViewController ,UITableViewDelegate,UITableViewDataSource{
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 10
    }
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headView = UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 10))
        return headView
    }
    func tableView(_ tableView: UITableView, estimatedHeightForFooterInSection section: Int) -> CGFloat {
        return 10
    }
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let headView = UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 10))
        return headView
    }
    
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return 5
        }
        return 1
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.section == 0 && indexPath.row == 0 {
            return 80
        }
        return 44
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
       
        if indexPath.section == 0  {
            
            if indexPath.row == 0{
                let infoCell:InfoCell = tableView.dequeueReusableCell(withIdentifier: "InfoCell") as! InfoCell
                infoCell.selectionStyle = .none
                infoCell.accessoryType = .disclosureIndicator
                return infoCell
            }
            if indexPath.row == 3{
                let cell = UITableViewCell.init(style: .value1, reuseIdentifier: "cellId")
                cell.selectionStyle = .none
                cell.accessoryType = .disclosureIndicator
                cell.textLabel?.text = "我的二维码"
                return cell
            }else{
                let textArr = ["头像","名字","微信号","我的二维码","更多"]
                let arrrrr = ["","Kobe Bryant","TM真的是要醉到坟头草100米高了","",""]
                
                
                let cell = UITableViewCell.init(style: .value1, reuseIdentifier: "cellId")
                cell.selectionStyle = .none
                if indexPath.row != 2{
                    cell.accessoryType = .disclosureIndicator
                }
                cell.textLabel?.text = textArr[indexPath.row]
                cell.detailTextLabel?.text = arrrrr[indexPath.row]
                cell.detailTextLabel?.font = UIFont.systemFont(ofSize: 14)
                return cell
            }
            
            
        }else{
            let cell = UITableViewCell.init(style: .default, reuseIdentifier: "cellId")
            cell.selectionStyle = .none
            cell.accessoryType = .disclosureIndicator
            cell.textLabel?.text = "我的地址"
            return cell
        }

    }
    
    
    
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.row != 2 {
            
            if indexPath.section == 0{
                //
                switch indexPath.row {
                case 0:
                    let headVC = HeadViewVC()
                    headVC.headImage = UIImage.init(named: "father")
                    headVC.fromWhere = 1
                    self.navigationController?.pushViewController(headVC, animated: true)
                    break
                case 1:
                    
                    break
                case 3:
                    //二维码
                     let headVC = HeadViewVC()
                     headVC.fromWhere = 2
                     self.navigationController?.pushViewController(headVC, animated: true)
                    break
                case 4:
                    let moreVC = MoreViewController()
                    self.navigationController?.pushViewController(moreVC, animated: true)
                    break
                default:
                    
                    break
                }
                
            }else{
                //我的地址
                let addressVC = AddressViewController()
                self.navigationController?.pushViewController(addressVC, animated: true)
            }
            
        
        }
       
    }
    
   
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        self.titleLabel.text = "个人信息"

        var table = UITableView.init(frame: CGRect(x: 0, y: CGFloat(kStatus_Navigation_height), width: SCREEN_WIDTH, height: SCRENN_HEIGHT - CGFloat(kStatus_Navigation_height)), style: .grouped)
        
        table.delegate = self
        table.dataSource = self
        view.addSubview(table)
        table.register(UINib.init(nibName: "InfoCell", bundle: Bundle.main), forCellReuseIdentifier: "InfoCell")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
